Temp Skip Lists

Hello!

I'm currently developping a script that is supposed to get informations from a module and put them in skip Lists that will kind of "formalise" some blocks of texts.

The script does this :
Get info, put it in a temp Skip list 1, put temp Skip 1 on a global skip list 2.

When I try to get data from Skip List 2 the only thing I get is the last temp Skip list 1 I put in.
I figured that was because the put() function for Skip didn't actually copy the temp skip list in Skip 2 but only made a link toward it.
That would be why when I try to get data, I only get the last thing I put in temp Skip 1.

My problem is that I don't know how to keep all data in Skip 2.
I tried to create and delete new temp Skip in the main loop that fill them but when I try to access them on Skip 2, I get an ACCESS VIOLATION EXCEPTION...

I'm on DOORS 7.1, is there a way to do this ?
SystemAdmin - Tue Jun 09 09:14:49 EDT 2009

Re: Temp Skip Lists
Tony_Goodman - Tue Jun 09 09:41:30 EDT 2009

As you have found out, putting one skip list into another does not copy the contents, it just stores the address of the original list. This means that you cannot reuse your list and expect the dat ato remain.

You will have to iterate through the contents of your skip list and add the items individually or keep the skip lists global and creaet more as you need them.

This sort of data structure can get very confusing and error prone - what is it you are trying to do? There may be a better solution.

Re: Temp Skip Lists
SystemAdmin - Tue Jun 09 10:02:17 EDT 2009

First, thanks for your answer.

Well, I thought about putting evrything in a global skip list the only problem is that the elements I get from the module have basically the name name and I use string keys.
That is to say the structure is of this type:
<element1>
<type1>
<name1> <value> <value/> <name1/>
<name2> <value> <value/> <name2/>
....
<type1/>
<type2>
<name1> <value> <value/> <name1/>
<name2> <value> <value/> <name2/>
....
<type2/>
...
<element1/>

Since name1 and name2 are often the same, I created a temp Skip List that took {"type1" : value, "name1": value, "name2": value}
One loop fills the temp Skip List for an "element" and put it (or I want to put it) in something else that store data on all elements.

My purpose is to make of a block of text something that you can parse (XML like) since data is for the moment pure text (which still has some patterns that I try to parse)

Any idea ?

Re: Temp Skip Lists
SystemAdmin - Tue Jun 09 10:02:28 EDT 2009

First, thanks for your answer.

Well, I thought about putting evrything in a global skip list the only problem is that the elements I get from the module have basically the name name and I use string keys.
That is to say the structure is of this type:
<element1>
<type1>
<name1> <value> <value/> <name1/>
<name2> <value> <value/> <name2/>
....
<type1/>
<type2>
<name1> <value> <value/> <name1/>
<name2> <value> <value/> <name2/>
....
<type2/>
...
<element1/>

Since name1 and name2 are often the same, I created a temp Skip List that took {"type1" : value, "name1": value, "name2": value}
One loop fills the temp Skip List for an "element" and put it (or I want to put it) in something else that store data on all elements.

My purpose is to make of a block of text something that you can parse (XML like) since data is for the moment pure text (which still has some patterns that I try to parse)

Any idea ?

Re: Temp Skip Lists
Peter_Albert - Tue Jun 09 10:06:17 EDT 2009

As Tony said, you have to be extra careful when creating nested skip lists, i.e. skip lists which have skip lists as values. To start with, deleting the "outer" skip list does not free the memory of the inner skip lists, thus you must explicitly delete the inner skip lists to avoid memory leaks. Secondly, it is extra easy to get ACCESS VIOLATION errors, as you already experienced. In your case, deleting the tempSkip in the main loop and then accessing it from Skip 2 was the key to the error, as, again as Tony said, only the address to the skip list is stored.

However, from time to time a construction like this comes in handy, so here is a DXL framework you can probably build upon. But again, you must be careful

a) to always use the same variable types for keys and values when creating and reading the skip lists and values

b) not to delete skip lists or list elements before you use them

c) free the memory explicitely

Skip globalList
 
void deleteSkip(Skip sList)
{ // Delete nested skip list and free memory
  Skip s
  for s in sList do {delete s}
  delete sList
} // Delete nested skip list and free memory
 
void addSkip(int iGlobKey)
{ // Put a local skip list into the global variable
  Skip localList = create
  int nValue = random(5) + 1
  int i
  for i in 0:nValue - 1 do 
  { // Create a local skip list
    put(localList, i, "A random number: " (random 100) "")
  } // Create a local skip list
  put(globalList, iGlobKey, localList)
  // Do no delete the localList here, as this would result in 
  // EXCEPTION_ACCESS_VIOLATION errors when you try to access them via
  // the global skip list later
} // Put a local skip list into the global variable
 
void printAllValues()
{ // Print all values from all stored skip lists
  // You must be very careful here that the data types used as keys
  // and values in the local and global skip list during creation match the
  // ones used here
  Skip localList
  int iKey, iGlobalKey
  string sValue
  for localList in globalList do
  { // Loop hrough local skip lists
    iGlobalKey = (int key globalList)
    for sValue in localList do
    { // Loop through local Lists's values
      iKey = (int key localList)
      print ""//
      "Global key : " iGlobalKey " | "//
      "Local key : " iKey " | "//
      "Local value : " sValue "\n"
    } // Loop through local Lists's values
  } // Loop hrough local skip lists
} // Print all values from all stored skip lists
 
// Main
globalList = create()
 
addSkip(1)
addSkip(2)
printAllValues()
deleteSkip(globalList)


Regards,

Peter

Re: Temp Skip Lists
llandale - Tue Jun 09 14:13:38 EDT 2009

Peter_Albert - Tue Jun 09 10:06:17 EDT 2009

As Tony said, you have to be extra careful when creating nested skip lists, i.e. skip lists which have skip lists as values. To start with, deleting the "outer" skip list does not free the memory of the inner skip lists, thus you must explicitly delete the inner skip lists to avoid memory leaks. Secondly, it is extra easy to get ACCESS VIOLATION errors, as you already experienced. In your case, deleting the tempSkip in the main loop and then accessing it from Skip 2 was the key to the error, as, again as Tony said, only the address to the skip list is stored.

However, from time to time a construction like this comes in handy, so here is a DXL framework you can probably build upon. But again, you must be careful

a) to always use the same variable types for keys and values when creating and reading the skip lists and values

b) not to delete skip lists or list elements before you use them

c) free the memory explicitely

Skip globalList
 
void deleteSkip(Skip sList)
{ // Delete nested skip list and free memory
  Skip s
  for s in sList do {delete s}
  delete sList
} // Delete nested skip list and free memory
 
void addSkip(int iGlobKey)
{ // Put a local skip list into the global variable
  Skip localList = create
  int nValue = random(5) + 1
  int i
  for i in 0:nValue - 1 do 
  { // Create a local skip list
    put(localList, i, "A random number: " (random 100) "")
  } // Create a local skip list
  put(globalList, iGlobKey, localList)
  // Do no delete the localList here, as this would result in 
  // EXCEPTION_ACCESS_VIOLATION errors when you try to access them via
  // the global skip list later
} // Put a local skip list into the global variable
 
void printAllValues()
{ // Print all values from all stored skip lists
  // You must be very careful here that the data types used as keys
  // and values in the local and global skip list during creation match the
  // ones used here
  Skip localList
  int iKey, iGlobalKey
  string sValue
  for localList in globalList do
  { // Loop hrough local skip lists
    iGlobalKey = (int key globalList)
    for sValue in localList do
    { // Loop through local Lists's values
      iKey = (int key localList)
      print ""//
      "Global key : " iGlobalKey " | "//
      "Local key : " iKey " | "//
      "Local value : " sValue "\n"
    } // Loop through local Lists's values
  } // Loop hrough local skip lists
} // Print all values from all stored skip lists
 
// Main
globalList = create()
 
addSkip(1)
addSkip(2)
printAllValues()
deleteSkip(globalList)


Regards,

Peter

This looks right. Yes, the local Skips are stored not a copy of them.

Advise you to carefully comment how each skip is being used so you (and future readers of your code) don't get confused.

Don't forget to delete the internal Skips before deleting the global skip:

//***********************
void    fSkipDelSkip(Skip &skpIn)
{     // Delete the Skip list, first deleting all the 'Skip' list DATA elements.
        // Be sure the Skip's DATA is type 'Skip'.
 
        if (null skpIn) return
 
        Skip    skpData
 
        for skpData in skpIn do
        {  delete(skpData)
        }
        delete(skpIn)
}     // end fSkipDelSkip()

 


You will have similar functions when you store Buffers and DXLObjects as the Data in some Skip list.

-Louie

 

Re: Temp Skip Lists
SystemAdmin - Wed Jun 10 04:54:03 EDT 2009

Hello !

Thanks for your answers !

Indeed, this might be helpful, I think that was what I was looking for.

Again, thank you!

Regards.